<template>
    <!-- 添加或修改派工产品对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body :close-on-click-modal="false" v-dialogDrag>
        <el-form ref="form" :model="form" :rules="rules" label-width="120px">
            <el-tabs v-model="activeName" class="detail-tab" type="card">
                <el-tab-pane label="基本信息" name="first">
                    <el-row :gutter="20">
                        <el-col :span="12">
                            <el-form-item label="工程名称" prop="gongchengName">
                                <el-input v-model="form.gongchengName" placeholder="请输入工程名称"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="商品id" prop="goodsId">
                                <el-input v-model="form.goodsId" placeholder="请输入商品id"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="产品名称" prop="goodsName">
                                <el-input v-model="form.goodsName" placeholder="请输入产品名称"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="合同交货日期" prop="deliveryTime">
                                <el-date-picker clearable
                                                v-model="form.deliveryTime"
                                                type="date"
                                                value-format="yyyy-MM-dd"
                                                placeholder="请选择合同交货日期">
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="合同物料名称" prop="contractGoodsName">
                                <el-input v-model="form.contractGoodsName" placeholder="请输入合同物料名称"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="项目负责人" prop="chargePerson">
                                <el-input v-model="form.chargePerson" placeholder="请输入项目负责人"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="产品编码" prop="goodsCode">
                                <el-input v-model="form.goodsCode" placeholder="请输入产品编码"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="产品型号明细" prop="goodsBrand">
                                <el-input v-model="form.goodsBrand" placeholder="请输入产品型号明细"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="产品型号" prop="goodModel">
                                <el-input v-model="form.goodModel" placeholder="请输入产品型号"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="销售单价" prop="goodsUnitPrice">
                                <el-input v-model="form.goodsUnitPrice" placeholder="请输入销售单价"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="锁定数量" prop="lockCount">
                                <el-input v-model="form.lockCount" placeholder="请输入锁定数量"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="总价" prop="goodsTotalPrice">
                                <el-input v-model="form.goodsTotalPrice" placeholder="请输入总价"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="成本单价" prop="goodsBuyPrice">
                                <el-input v-model="form.goodsBuyPrice" placeholder="请输入成本单价"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="成本金额" prop="goodsBuyTotal">
                                <el-input v-model="form.goodsBuyTotal" placeholder="请输入成本金额"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="销售利润" prop="goodsProfit">
                                <el-input v-model="form.goodsProfit" placeholder="请输入销售利润"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="含税单价" prop="goodsTaxUnitPrice">
                                <el-input v-model="form.goodsTaxUnitPrice" placeholder="请输入含税单价"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="含税总价" prop="goodsTaxTotalPrice">
                                <el-input v-model="form.goodsTaxTotalPrice" placeholder="请输入含税总价"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="请购数量" prop="pleaseBuyCount">
                                <el-input v-model="form.pleaseBuyCount" placeholder="请输入请购数量"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="订单数量" prop="orderCount">
                                <el-input v-model="form.orderCount" placeholder="请输入订单数量"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="销售日期" prop="saleDate">
                                <el-date-picker clearable
                                                v-model="form.saleDate"
                                                type="date"
                                                value-format="yyyy-MM-dd"
                                                placeholder="请选择销售日期">
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="供应商" prop="supplierId">
                                <el-input v-model="form.supplierId" placeholder="请输入供应商"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="供应商名称" prop="supplierName">
                                <el-input v-model="form.supplierName" placeholder="请输入供应商名称"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="客户" prop="customerId">
                                <el-input v-model="form.customerId" placeholder="请输入客户"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="客户名称" prop="customerName">
                                <el-input v-model="form.customerName" placeholder="请输入客户名称"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="是否开票" prop="invoice">
                                <el-input v-model="form.invoice" placeholder="请输入是否开票"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="发票id" prop="invoiceId">
                                <el-input v-model="form.invoiceId" placeholder="请输入发票id"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="发票编号" prop="invoiceNo">
                                <el-input v-model="form.invoiceNo" placeholder="请输入发票编号"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="是否回款" prop="fundCallback">
                                <el-input v-model="form.fundCallback" placeholder="请输入是否回款"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="是否打印签收单" prop="receipt">
                                <el-input v-model="form.receipt" placeholder="请输入是否打印签收单"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="销售人" prop="saleId">
                                <el-input v-model="form.saleId" placeholder="请输入销售人"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="销售人姓名" prop="saleName">
                                <el-input v-model="form.saleName" placeholder="请输入销售人姓名"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="删除标志" prop="delFlag">
                                <el-input v-model="form.delFlag" placeholder="请输入删除标志"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="备注" prop="remark">
                                <el-input v-model="form.remark" placeholder="请输入备注"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="订单编号" prop="projectId">
                                <el-input v-model="form.projectId" placeholder="请输入订单编号"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="订单名称" prop="projectName">
                                <el-input v-model="form.projectName" placeholder="请输入订单名称"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="订单编号" prop="projectNo">
                                <el-input v-model="form.projectNo" placeholder="请输入订单编号"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="部门ID" prop="deptId">
                                <el-input v-model="form.deptId" placeholder="请输入部门ID"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="部门名称" prop="deptName">
                                <el-input v-model="form.deptName" placeholder="请输入部门名称"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="是否发货'0'" prop="isfahuo">
                                <el-input v-model="form.isfahuo" placeholder="请输入是否发货'0'"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="发货时间" prop="fahuoDate">
                                <el-date-picker clearable
                                                v-model="form.fahuoDate"
                                                type="date"
                                                value-format="yyyy-MM-dd"
                                                placeholder="请选择发货时间">
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="回款时间" prop="huikuanDate">
                                <el-date-picker clearable
                                                v-model="form.huikuanDate"
                                                type="date"
                                                value-format="yyyy-MM-dd"
                                                placeholder="请选择回款时间">
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="产品编码" prop="code">
                                <el-input v-model="form.code" placeholder="请输入产品编码"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="是否自制(1:自制; 2:请购; 3:外协)" prop="isdo">
                                <el-input v-model="form.isdo" placeholder="请输入是否自制(1:自制; 2:请购; 3:外协)"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="已发货数量" prop="fahuoCount">
                                <el-input v-model="form.fahuoCount" placeholder="请输入已发货数量"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="剩余发货" prop="fahuoShengyu">
                                <el-input v-model="form.fahuoShengyu" placeholder="请输入剩余发货"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="请购单id" prop="lvdoId">
                                <el-input v-model="form.lvdoId" placeholder="请输入请购单id"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="请购单编号" prop="lvdoNo">
                                <el-input v-model="form.lvdoNo" placeholder="请输入请购单编号"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="工艺id" prop="gongyiId">
                                <el-input v-model="form.gongyiId" placeholder="请输入工艺id"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="工艺名称" prop="gongyiName">
                                <el-input v-model="form.gongyiName" placeholder="请输入工艺名称"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="工艺编号" prop="gongyiCode">
                                <el-input v-model="form.gongyiCode" placeholder="请输入工艺编号"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="24">
                            <el-form-item label="工艺文件">
                                <file-upload v-model="form.gongyiFile"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="工艺图纸" prop="gongyiPhoto">
                                <el-input v-model="form.gongyiPhoto" placeholder="请输入工艺图纸"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="工艺说明" prop="gongyiShuoming">
                                <el-input v-model="form.gongyiShuoming" placeholder="请输入工艺说明"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="工艺工序及分配任务状态" prop="state">
                                <el-input v-model="form.state" placeholder="请输入工艺工序及分配任务状态"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="24">
                            <el-form-item label="巡检记录单">
                                <file-upload v-model="form.xunjianFile"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="入库数量" prop="rukuCount">
                                <el-input v-model="form.rukuCount" placeholder="请输入入库数量"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="未入库数量" prop="weiruCount">
                                <el-input v-model="form.weiruCount" placeholder="请输入未入库数量"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="合同收货人" prop="deliveryPerson">
                                <el-input v-model="form.deliveryPerson" placeholder="请输入合同收货人"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="${comment}" prop="rukumingxiId">
                                <el-input v-model="form.rukumingxiId" placeholder="请输入${comment}"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="${comment}" prop="rukumingxiNo">
                                <el-input v-model="form.rukumingxiNo" placeholder="请输入${comment}"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="是否拆解" prop="ischaijie">
                                <el-input v-model="form.ischaijie" placeholder="请输入是否拆解"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="排序" prop="sort">
                                <el-input v-model="form.sort" placeholder="请输入排序"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="项目单位" prop="projectDept">
                                <el-input v-model="form.projectDept" placeholder="请输入项目单位"/>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-tab-pane>
            </el-tabs>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
        </div>
    </el-dialog>
</template>

<script>
    import { addAction, getById, updateAction } from '@/api/manage';
    import moment from 'moment';

    export default {
        name: "GoodsSaleToworkForm",
        data() {
            return {
                // 遮罩层
                loading: true,
                activeName: "first",
                // 弹出层标题
                title: "",
                // 是否显示弹出层
                open: false,
                // 表单参数
                form: {},
                // 表单校验
                rules: {
                },
                url: {
                    getById:'/goodsSaleTowork/goodsSaleTowork/',
                    add:'/goodsSaleTowork/goodsSaleTowork/add',
                    edit:'/goodsSaleTowork/goodsSaleTowork/edit',
                },
            };
        },
        created() {

        },
        methods: {
            // 取消按钮
            cancel() {
                this.open = false;
                this.reset();
            },
            // 表单重置
            reset() {
                this.form = {
            id: null,
            type: null,
            gongchengName: null,
            goodsId: null,
            goodsName: null,
            deliveryTime: null,
            contractGoodsName: null,
            chargePerson: null,
            goodsCode: null,
            goodsType: null,
            goodsBrand: null,
            goodModel: null,
            goodsUnitPrice: null,
            lockCount: null,
            goodsTotalPrice: null,
            goodsBuyPrice: null,
            goodsBuyTotal: null,
            goodsProfit: null,
            goodsTaxUnitPrice: null,
            goodsTaxTotalPrice: null,
            pleaseBuyCount: null,
            orderCount: null,
            saleDate: null,
            supplierId: null,
            supplierName: null,
            customerId: null,
            customerName: null,
            invoice: null,
            invoiceId: null,
            invoiceNo: null,
            fundCallback: null,
            receipt: null,
            saleId: null,
            saleName: null,
            delFlag: null,
            createBy: null,
            createTime: null,
            updateBy: null,
            updateTime: null,
            remark: null,
            projectId: null,
            projectName: null,
            projectNo: null,
        status: "0",
            deptId: null,
            deptName: null,
            isfahuo: null,
            fahuoDate: null,
            huikuanDate: null,
            code: null,
            isdo: null,
            fahuoCount: null,
            fahuoShengyu: null,
            lvdoId: null,
            lvdoNo: null,
            gongyiId: null,
            gongyiName: null,
            gongyiCode: null,
            gongyiFile: null,
            gongyiPhoto: null,
            gongyiShuoming: null,
            state: null,
            xunjianFile: null,
            rukuCount: null,
            weiruCount: null,
            deliveryPerson: null,
            rukumingxiId: null,
            rukumingxiNo: null,
            ischaijie: null,
            sort: null,
            caigouType: null,
            projectDept: null
                };
                this.resetForm("form");
            },
            /** 新增按钮操作 */
            handleAdd() {
                this.reset();
                this.open = true;
                this.title = "添加派工产品";
            },
            /** 修改按钮操作 */
            handleUpdate(row) {
                this.reset();
                const id = row.id || this.ids;
                getById(this.url.getById, id).then(response => {
                    this.form = response.data;
                    this.open = true;
                    this.title = "修改派工产品";
                });
            },
            /** 提交按钮 */
            submitForm() {
                this.$refs["form"].validate(valid => {
                    if (valid) {
                        if (this.form.id != null) {
                            updateAction(this.url.edit, this.form).then(response => {
                                this.$modal.msgSuccess("修改成功");
                                this.open = false;
                                this.$emit('ok');
                            });
                        } else {
                            addAction(this.url.add, this.form).then(response => {
                                this.$modal.msgSuccess("新增成功");
                                this.open = false;
                                this.$emit('ok');
                            });
                        }
                    }
                });
            },
        }
    };
</script>
